#pragma once 
#include"UdpSocket.h"
#include "EventLoop.h"
#include "UdpSocket.h"
#include "InetAddress.h"
#include<functional>

namespace tmms
{
    namespace network
    {
        using ConnectedCallback = std::function<void (const UdpSocketPtr&,bool)>;
       
        class UdpClient:public UdpSocket
        {
        private:
            bool connected_{false};
            InetAddress server_addr_;
            ConnectedCallback connected_cb_;
            struct sockaddr_in6 sock_addr_;
            socklen_t sock_len_{sizeof(struct sockaddr_in6)};
        public:
            UdpClient(EventLoop *loop,const InetAddress &server);
            void Connect();
            void SetConnectedCallback(const ConnectedCallback &cb);
            void SetConnectedCallback( ConnectedCallback &&cb);

            void ConnectInLoop();
            void Send(std::list<BufferNodePtr> &list);
            void Send(const char* buf,size_t size);
            void OnClose() override;
            ~UdpClient();
        };
        

    }
}